package LanQiao.jichu;

import java.math.BigInteger;
import java.util.Scanner;

//进制转换
public class BASIC_12 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] ret = new String[n];
        for (int i = 0; i < n; i++) {
            String s = scanner.next();
            BigInteger a = new BigInteger(s,16);
            String str = a.toString(8);
            ret[i] = str;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ret[i]);
        }
    }
}
